<?php

/**
  Document   : present_list
  Created on : 18.06.2013., 20.11.46
  Author     : Sasa
  Description:
 */
?>
<link rel="stylesheet" href="<?php echo base_url(); ?>css/style.css" />
 <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<script>
  $(function() {
    $( "#selectable" ).selectable({      
      stop: function() {
        var result = $( "#select-result" ).empty();
        $( ".ui-selected", this ).each(function() {
          var index = $( "#selectable li" ).index( this );
          result.replaceWith( " #" + ( index + 1 ) );
        });
      }
    });
    //$( "#selectable" ).multiselect("disable");
    $( ".present" ).click(
      function(){
        var present = $(this).attr('alt');
        //alert(present);
        $( "#selected_present" ).val(present);
      }
    );
    
    $( "#send_present" ).click(
      function()
      {
        var present = $( "#selected_present" ).val();
        var to_id = $( "#to_id" ).val();
        if( "" != present )
        {
          //alert(present);
          send_present(present,to_id);          
        }  
        else
          alert("<?php echo lang('present_not_selected'); ?>");
      }
    );
    
  });
  
  
  function send_present(present,to_id)
  {
      var ajaxURL = BASE_URL + 'presents/sendPresent';
    
        // Ajax upit
        $.ajax({  
            type: "POST", 
            url: ajaxURL,
            data: 'present='+present+"&to_id="+to_id,
            cache: false,
            async: false,
            success: function(response){

                var parsed = JSON.parse(response);
                var html = '';
                html = parsed.msg;
                $("#response_present").show().html(html).delay(3000).hide(500);
                            
            }  
        }); // end AJAX upita
  }
 
</script>

<div class="choose-present">
        <h3><?php echo lang('select_presenting'); ?></h3>
        <ol id="selectable">
            <li class="ui-widget-content ui-selected"><img class="present" src="<?php echo base_url(); ?>img/presents/thumb/heart01.png" width="100" height="100" alt="heart01"></li>
            <li class="ui-widget-content"><img class="present"  src="<?php echo base_url(); ?>img/presents/thumb/heart02.png" width="100" height="100" alt="heart02"></li>
            <li class="ui-widget-content"><img class="present"  src="<?php echo base_url(); ?>img/presents/thumb/heart03.png" width="100" height="100" alt="heart03"></li>
            <li class="ui-widget-content"><img class="present" src="<?php echo base_url(); ?>img/presents/thumb/kiss.png" width="100" height="100" alt="kiss"></li>
            <li class="ui-widget-content"><img class="present"  src="<?php echo base_url(); ?>img/presents/thumb/letter.png" width="100" height="100" alt="letter"></li>
            <li class="ui-widget-content"><img class="present" src="<?php echo base_url(); ?>img/presents/thumb/lollipop.png" width="100" height="100" alt="lollipop"></li>
            <li class="ui-widget-content"><img class="present" src="<?php echo base_url(); ?>img/presents/thumb/present.png" width="100" height="100" alt="present"></li>
            <li class="ui-widget-content"><img class="present" src="<?php echo base_url(); ?>img/presents/thumb/rose.png" width="100" height="100" alt="rose"></li>
        </ol>
        <div class="clr"></div>
        <div id='response_present'></div>
        <div class="clr"></div>
        <input type="hidden" value='heart01' id="selected_present" />
        <input type="hidden" value="<?php echo $to_id; ?>" id="to_id" />
        <input class="save" id="send_present" name="" type="button" value="<?php echo sprintf(lang('send_present_an'),$this->config->item('present_cost'))." ".$name; ?>">
        </div>

